extends "../ib.gd"
var cnt
var cnt2
var cell
func init():
	.init()
	name = "琵琶"
	resetdata()
	att.atk = 30
	att.cd = 0.05
	att.mgiPen = 5
	info = "魔音贯耳：向距离最远的敌方单位发射声波，对路径上所有人（不分敌我）造成33%物攻魔法伤害，并对该单位造成80%物攻魔法伤害且附加1层<魔音散发>[cd:5秒]\n"
#根据等级增加属性
func addatt():
	att.atk += 20
	att.cd += 0.07
	att.penL += 0.05
	att.mgiPenL += 0.05
#链接信号
func _connect():
	._connect()
	yield(sys.get_tree().create_timer(0.05),"timeout")
	if !masCha:return
	sys.main.connect("onBattleStart",self,"resetcnt")
	if !masCha.is_connected("onAddItem",self,"check"):
		masCha.connect("onAddItem",self,"check")
#检查是否只有一双鞋
func check(item):
	yield(sys.get_tree().create_timer(0.02),"timeout")
	if item.id.find("pipa") != -1 && item != self:
		masCha.delItem(item)
		sys.newBaseMsg("提示","一个角色只能装备一把琵琶")
#重置技能计数
func resetcnt():
	cnt = 0
	cnt2 = 0
#进化装备
func upgradeself(item):
	var chose = item.chose
	var c = str(chose)
	var upid = "_Hide_MAX"
	upid = self.id + upid
	self.switchchose(chose)
	var nitem = sys.newItem(upid)
	sys.main.player.addItem(nitem)
	masCha.disconnect("onAddItem",self,"check")
	masCha.addItem(nitem)
	nitem.inheritatt(nitem,self)
	nitem.addatt()
	nitem.upinfo()
	self.delself()

#技能计时
func _upS():
	._upS()
	cnt += 1
	if cnt == 5:
		cnt = 0
		myge()

func myge():
	cell = masCha.cell
	var chas = masCha.getAllChas(1)
	chas.sort_custom(self,"sort")
	var chas2 = utils.lineChas(cell,chas[0].cell,10)
	for i in chas2:
		masCha.hurtChara(i,masCha.att.atk*0.33,Chara.HurtType.MGI,Chara.AtkType.SKILL)
	masCha.hurtChara(chas[0],masCha.att.atk*0.8,Chara.HurtType.MGI,Chara.AtkType.SKILL)
	chas[0].addBuff(MYSF.new(masCha.att.atk*0.3,masCha))

func sort(a,b):
	var x1 = abs(a.cell.x - cell.x)
	var x2 = abs(b.cell.x - cell.x)
	var y1 = abs(a.cell.y - cell.y)
	var y2 = abs(b.cell.y - cell.y)
	return (x1*x1 + y1*y1) > (x2*x2 + y2*y2)

class MYSF:
	extends Buff
	var dmg
	var cha 
	var ctrl = globalData.infoDs["g_AneHek"]
	func _init(dmg,cha):
		attInit()
		life = 2.0
		id = "MYSF"
		self.dmg = dmg
		self.cha = cha
	func _upS():
		var chas = masCha.getAllChas(2)
		for i in chas:
			if abs(i.cell.x - masCha.cell.x) * abs(i.cell.x - masCha.cell.x) <= 1 && abs(i.cell.y - masCha.cell.y) * abs(i.cell.y - masCha.cell.y) <= 1:
				if sys.rndPer(33):
					i.addBuff(ctrl.b_hl.new(1))
					if cha:
						cha.hurtChara(i,dmg,Chara.HurtType.MGI,Chara.AtkType.EFF)
					else:
						i.hurtChara(i,dmg,Chara.HurtType.MGI,Chara.AtkType.EFF)